<?php

require_once('bibliotecas/por.php');
require_once('bibliotecas/pdf_creator.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Victor Henrique');
$pdf->SetTitle('LIVRARIA EBENEZER');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 14, '', true);

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();

include($configurator["classes"] . "/produto.classes.php");
include($configurator["dao"] . "/produtoDao.php");

$_produto = new ProdutoDao();
$produtos = $_produto->listarProdutos();
$dados = "<table>
    <tr>
        <th>Código</th>
        <th>Título</th>
        <th>Categoria</th>
        <th>Ano</th>
        <th>Tipo</th>
    </tr>";

// Set some content to print
foreach ($produtos as $valor) {
    $codigo = $valor['codigo'];
    $titulo = $valor['titulo'];
    $categoria = $valor['categoria'];
    $ano = $valor['ano'];
    $tipo = $valor['tipo'];
 
    $dados .= '<tr>
                        <td>' . $codigo . '</td>
                        <td>' . $titulo . '</td>
                        <td>' . $categoria . '</td>
                        <td>' . $ano . '</td>
                        <td>' . $tipo . '</td>
                   </tr>';
}
$dados .="</table>";
$pdf->writeHTML($dados_loja, true, false, true, false, '');
$pdf->writeHTML($dados, true, false, true, false, '');

// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output('produto_listagem_pdf.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+

